package tianhao.luo.huffmancode;

/**
 * 带数据和权值
 * @author: tianhao.luo@hand-china.com 2021/6/26  上午8:32
 */
public class Node implements Comparable<Node>{
    /**
     * 数据域
     */
    Byte data;
    /**
     * 权重
     */
    int weight;

    Node left;

    Node right;

    public Node(Byte data, int weight) {
        this.data = data;
        this.weight = weight;
    }

    @Override
    public int compareTo(Node o) {
        return this.weight-o.weight;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Node{");
        sb.append("data=").append(data);
        sb.append(", weight=").append(weight);
        sb.append('}');
        return sb.toString();
    }

    public void preOrder(){
        System.out.println(this);


        if (this.left !=null){
            this.left.preOrder();
        }

        if (this.right !=null){
            this.right.preOrder();
        }
    }
}
